<template>
	<view id="view">
		<view class="item" v-for="(item,index) in approveList" :key="item.id">
			<u-cell title="姓名" :value="item.name"></u-cell>
			<u-cell title="学工号" :value="item.account"></u-cell>
			<u-cell title="出行日期" :value="utils.dateString(new Date(item.date_time))"></u-cell>
			<view class="textarea" v-text="item.reason"></view>
			<view style="width: 80vw;margin:10upx auto" class="flex-center-around">
				<view style="width: 40%;" class="flex-center-center">
					<u-button @click="choose(index, false)" type="primary" text="打回" color="#888"></u-button>
				</view>
				<view style="width: 40%;" class="flex-center-center">
					<u-button @click="choose(index, true)" type="primary" text="同意" color="var(--theme-color)"></u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				approveList:[]
			}
		},
		onLoad() {
			const that = this
			that.API({
				showLoading:true,
				url:'/user/approves',
				code0:function(res){
					that.approveList = res.data.data
				}
			})
		},
		methods: {
			choose(index, allow){
				const that = this
				that.API({
					showLoading:true,
					url:"/user/approve",
					method:'post',
					data:{
						approve_id:that.approveList[index].id,
						allow:allow
					},
					code0:function(){
						uni.showToast({
							title:"操作成功"
						})
						that.approveList.splice(index, 1)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	#view{
		.item{
			background-color: white;
			margin: 20upx 0;
			padding-bottom: 20upx;
			.textarea{
				height: 200upx;
				padding: 20upx;
				color: #666;
			}
		}
	}
</style>

